/*
 * MainServer.java
 *
 * Copyright 2012 the original author or authors(ninglong).
 *
 * Licensed under the testMina, Version 1.0 (the "License");
 *
 */
package org.geek.demo.mina.server;

import java.net.InetSocketAddress;
import java.nio.charset.Charset;

import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.transport.socket.SocketAcceptor;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;

/**   
 * <p>服务器端</p>
 * @author ninglong bhd2973@qq.com   
 * @date May 2, 2012 10:12:03 PM
 * @version V1.0   
 */
public class MainServer {
	public static void main(String[] args) throws Exception{
		//创建一个socket连接
		SocketAcceptor acceptor = new NioSocketAcceptor();
		//创建数据接收过滤器
		DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
		chain.addLast("mychain", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName( "UTF-8"))));
		//创建数据处理器
		acceptor.setHandler(new Server());
		//bind 端口
		acceptor.bind(new InetSocketAddress(8080));
		System.out.println("服务启动：端口8080");
	}
}
